package com.yangye.pidoublename.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author yangye
 * @date 2019/9/18
 */
@Component
public class DoubleNameServiceFactory implements ApplicationContextAware {

	private Map<String, DoubleNameService> beanMap;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		beanMap = applicationContext.getBeansOfType(DoubleNameService.class);
	}

	public DoubleNameService getDoubleNameService(String province) {
		String beanName = ProvinceEnum.getByCode(province).getBeanName();
		return beanMap.get(beanName);
	}
}
